public class Demo3 {
    public static void main(String[] args) {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread thread1 = new Thread(() -> {
            synchronized(locker1) {
                System.out.println(Thread.currentThread().getName());
            }
            synchronized(locker2) {
                System.out.println(Thread.currentThread().getName());
            }
        });

        Thread thread2 = new Thread(() -> {
            synchronized(locker2) {
                System.out.println(Thread.currentThread().getName());
            }
            synchronized(locker1) {
                System.out.println(Thread.currentThread().getName());
            }
        });

        thread1.start();
        thread2.start();
    }
}
